package org.o2opuzi.ms.lib;

import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;

import com.alibaba.fastjson.JSONArray;
import com.o2opuzi.lib.http.Http;

public class DTIPClient {
	
	static int count = 0;
	
	public static void run(final String ip,final int port){
		
		try {
			Http http = new Http("http://tpv2.scol.com.cn/netvote/16sclytop/safecodeusing");
			RequestConfig config = RequestConfig.custom().setProxy(new HttpHost(ip, port)).setAuthenticationEnabled(true).build();
			http.setConfig(config);
			http.addHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1");
			http.addHeader("X-Requested-With", "XMLHttpRequest");
			http.addHeader("Host", "tpv2.scol.com.cn");
			http.addHeader("Referer", "http://tpv2.scol.com.cn/16sclytop/");
			http.addHeader("Origin", "http://tpv2.scol.com.cn");
			http.addHeader("Cookie", "Hm_lvt_0f827d2d0df4dc71c86b6160f1a1970c=1483675024; Hm_lpvt_0f827d2d0df4dc71c86b6160f1a1970c=1483675024");
			http.doPost().toString();
			Thread.sleep(1000);
			Http http2 = new Http("http://tpv2.scol.com.cn/netvote/16sclytop");
			RequestConfig config2 = RequestConfig.custom().setProxy(new HttpHost(ip, port)).setAuthenticationEnabled(true).build();
			http2.setConfig(config2);
			http2.addHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1");
			http2.addHeader("X-Requested-With", "XMLHttpRequest");
			http2.addHeader("Host", "tpv2.scol.com.cn");
			http2.addHeader("Referer", "http://tpv2.scol.com.cn/16sclytop/");
			http2.addHeader("Origin", "http://tpv2.scol.com.cn");
			http2.addHeader("Cookie", "Hm_lvt_0f827d2d0df4dc71c86b6160f1a1970c=1483675024; Hm_lpvt_0f827d2d0df4dc71c86b6160f1a1970c=1483675024");
			http2.addParam("myitem", "33902");
			String ret = http2.doPost().toString();
			if(ret.indexOf("推荐成功") == -1){
				System.out.println("投票失败：："+ret);
			}else{
				count++;
				System.out.println(ret+"  ip:::"+ip);
				System.out.println("已投："+count);
			}
		
		} catch (Exception e) {
			System.out.println("投票失败：："+e.getMessage());
		}
	}
	
	public static String[] getIpInfo(){
		Http http = new Http("http://api.ip.data5u.com/dynamic/get.html?order=610ad77d2fe41ef931c1f4be1e5b5217");
		String[] array = http.doGet().toString().split(":");
		return array;
	}
	
	public static void main(String[] args) throws Exception {
		while(true){
			
			String[] array = getIpInfo();
			
			new Thread(new P2(array[0], Integer.parseInt(array[1].trim()))).start();
			
			Thread.sleep(10000);
		}
		
	}
}

class P2 implements Runnable{
	String ip;
	
	int port;

	@Override
	public void run() {
		for (int i = 0; i < 8; i++) {
			try {
				DTIPClient.run(ip, port);
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public P2(String ip, int port) {
		super();
		this.ip = ip;
		this.port = port;
	}
	
	
	
	
}
